//
//  EFNavigationItemView.m
//  EFHealth
//
//  Created by nf on 15/12/22.
//  Copyright © 2018年 ef. All rights reserved.
//

#import "EFNavigationBarView.h"
#import "AppMacro.h"
#import "PublicUtils.h"

#define kNav_float_normal 19.0f
#define kNav_float_mini 14.0f

#define kNav_color_normal [UIColor whiteColor]
#define kNav_color_light [UIColor blackColor]

@interface EFNavigationBarView()

@property (nonatomic,strong)UILabel *titleLabel ;
@property (nonatomic,strong)UIButton *leftButton ;
@property (nonatomic,strong)UIButton *rightButton ;

@end

@implementation EFNavigationBarView


- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        
        self.backgroundColor = [UIColor whiteColor];
        
        UIView *line = [[UIView alloc]initWithFrame:CGRectMake(0, KNavFullHeight-0.5f, SCREEN_WIDTH, 0.5f)];
//        line.backgroundColor = kColor(59, 131, 210) ;
        line.backgroundColor = kColorLine ;
        [self addSubview:line];
    }
    
    return self ;
}

- (void)removeLeftButton
{
    if (_leftButton) {
        [_leftButton removeFromSuperview];
        [StateHeight dev_navigationFullHeight];
    }
}

- (void)removeRightButton
{
    if (_rightButton) {
        [_rightButton removeFromSuperview];
    }
}
- (void)addTitle:(NSString *)title
{
    self.titleLabel.text = title ;
    
//    [self.titleLabel sizeToFit];
    
//    self.titleLabel.center = CGPointMake(self.center.x, self.center.y+10);
    self.titleLabel.centerX =self.centerX;
}

- (UIButton *)addLeftButtonIcon:(NSString *)icon selecter:(SEL)selecter
{
    [self.leftButton setImage:kImage(icon) forState:UIControlStateNormal];
//    self.leftButton.imageEdgeInsets = UIEdgeInsetsMake(25+4, 5+10, 10, 55+16);
    self.leftButton.imageEdgeInsets = UIEdgeInsetsMake(10, 20, 10, 55);
    [self.leftButton addTarget:self.controlVC action:selecter forControlEvents:UIControlEventTouchUpInside];
   
    return self.leftButton ;
}
- (UIButton *)addLeftButtonTitle:(NSString *)title selecter:(SEL)selecter
{
    [self.leftButton setTitle:title forState:UIControlStateNormal];
    [self.leftButton addTarget:self.controlVC action:selecter forControlEvents:UIControlEventTouchUpInside];
    return self.leftButton ;
}

- (UIButton *)addRightButtonTitle:(NSString *)title selecter:(SEL)selecter
{
    [self.rightButton setTitle:title forState:UIControlStateNormal];
    [self.rightButton addTarget:self.controlVC action:selecter forControlEvents:UIControlEventTouchUpInside];
    return self.rightButton ;
}

- (UIButton *)addRightButtonIcon:(NSString *)icon selecter:(SEL)selecter
{
    [self.rightButton setImage:kImage(icon) forState:UIControlStateNormal];
    self.rightButton.imageEdgeInsets = UIEdgeInsetsMake(9, 45, 9, 10);// 80-25=55 43
//    self.rightButton.imageView.backgroundColor = [UIColor redColor];
    [self.rightButton addTarget:self.controlVC action:selecter forControlEvents:UIControlEventTouchUpInside];
    return self.rightButton ;
}

- (UIButton *)rightButton
{
    if (nil == _rightButton) {
        _rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _rightButton.frame = CGRectMake(SCREEN_WIDTH-90, KStatusBarHeight,80.0f, KNavBarHeight);
//        _rightButton.backgroundColor = [UIColor redColor];
        [_rightButton setTitleColor:kColorDefultCell forState:UIControlStateNormal];
        _rightButton.titleLabel.font = kFontBig ;
        _rightButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight ;
        [self addSubview:_rightButton];
    }
    return _rightButton ;
    
    
}
- (UIButton *)leftButton
{
    if (nil == _leftButton) {
        _leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _leftButton.frame = CGRectMake(0.0f, KStatusBarHeight, 100.0f, KNavBarHeight-1.0f);
        [_leftButton setTitleColor:kColorDefultCell forState:UIControlStateNormal];
        _leftButton.titleLabel.font = kFontBig ;
        [self addSubview:_leftButton];
    }
    return _leftButton ;
}
- (UILabel *)titleLabel
{
    if (nil == _titleLabel) {
        _titleLabel = [[UILabel alloc]initWithFrame:CGRectMake((SCREEN_WIDTH-100)/2, KStatusBarHeight, 100, KNavBarHeight)];
//        _titleLabel.font = [UIFont boldSystemFontOfSize:20];
        _titleLabel.font = [UIFont systemFontOfSize:17];
        _titleLabel.textColor = kTitleColor_black;
        _titleLabel.textAlignment = NSTextAlignmentCenter ;
        [self addSubview:_titleLabel];
    }
    return _titleLabel ;
}


@end

































